package com.bw.video2110

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import androidx.viewpager.widget.ViewPager
import androidx.viewpager2.widget.ViewPager2
import com.bawei.cinema.CinemaFragment
import com.bawei.home.ui.HomeFragment
import com.bawei.mine.MineFragment
import com.bw.lib_mvvm.BaseActivity
import com.bw.lib_mvvm.BaseMVVMActivity
import com.bw.video2110.adapter.ViewPagerAdapter
import com.bw.video2110.databinding.ActivityMainBinding
import com.google.android.material.bottomnavigation.BottomNavigationView

class MainActivity : BaseActivity<ActivityMainBinding>() {
    private val list = mutableListOf<Fragment>()
    override fun initView() {
        list.add(HomeFragment())
        list.add(CinemaFragment())
        list.add(MineFragment())

        val viewPagerAdapter = ViewPagerAdapter(list,supportFragmentManager)
        viewDataBinding.vpMain.adapter = viewPagerAdapter


        viewDataBinding.vpMain.addOnPageChangeListener(object :ViewPager.OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int,
            ) {
            }

            override fun onPageSelected(position: Int) {
                viewDataBinding.btmApp.menu.getItem(position).isChecked = true
            }

            override fun onPageScrollStateChanged(state: Int) {
            }
        })

        viewDataBinding.btmApp.setOnNavigationItemSelectedListener {
            when(it.itemId){
                R.id.home -> viewDataBinding.vpMain.currentItem= 0
                R.id.cinema -> viewDataBinding.vpMain.currentItem= 1
                R.id.mine -> viewDataBinding.vpMain.currentItem= 2
            }
            false
        }
    }

    override fun initData() {
    }

    override fun bindLayout() = R.layout.activity_main
}